package com.centaline.androidsalesblog.rx.request;

import com.android.volley.VolleyError;
import com.centaline.androidsalesblog.api.sale.BizBlobalApi;
import com.centaline.androidsalesblog.model.responseobject.BizGlobalRo;
import com.centanet.framework.interfaces.IResponseListener;

import rx.Observable;
import rx.Subscriber;

/**
 * 全局配置
 * Created by guilin on 16/2/4.
 */
final class RequestBizGlobalOnSubscribe implements Observable.OnSubscribe<BizGlobalRo> {

    private final Class<?> tag;

    RequestBizGlobalOnSubscribe(Class<?> tag) {
        this.tag = tag;
    }

    @Override
    public void call(final Subscriber<? super BizGlobalRo> subscriber) {
        new BizBlobalApi(tag, BizGlobalRo.class, new IResponseListener<BizGlobalRo>() {
            @Override
            public void onResponse(BizGlobalRo bizGlobalRo) {
                if (!subscriber.isUnsubscribed()) {
                    subscriber.onNext(bizGlobalRo);
                }
                subscriber.onCompleted();
            }

            @Override
            public void onErrorResponse(VolleyError error) {
                subscriber.onError(error);
            }
        }).startRequest();
    }
}
